package cn.cai.pethome.system.controller;

import cn.cai.pethome.system.service.ISystemdictionarydetailService;
import cn.cai.pethome.system.domain.Systemdictionarydetail;
import cn.cai.pethome.system.query.SystemdictionarydetailQuery;
import cn.cai.pethome.base.util.AjaxResult;
import cn.cai.pethome.base.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    public ISystemdictionarydetailService systemdictionarydetailService;


    /**
     * 查询宠物的颜色和宠物的品种
     * @param sn
     * @return
     */
    @GetMapping("/loadBySn/{sn}")
    public List<Systemdictionarydetail> loadBySn(@PathVariable("sn") String sn){
        return systemdictionarydetailService.loadBySn(sn);
    }


    /**
     * 保存和修改公用的
     * @param systemdictionarydetail  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping("/save")
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if( systemdictionarydetail.getId()!=null){
                    systemdictionarydetailService.update(systemdictionarydetail);
            }
            else{
                    systemdictionarydetailService.add(systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("保存对象失败！" + e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.deleteById(id);
            return AjaxResult.me();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.error("删除对象失败！" + e.getMessage());
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public Systemdictionarydetail get(@PathVariable("id")Long id)
    {
        return systemdictionarydetailService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping("/list")
    public List<Systemdictionarydetail> list(){
        return systemdictionarydetailService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/pagelist")
    public PageList<Systemdictionarydetail> json(@RequestBody SystemdictionarydetailQuery query)
    {
        return systemdictionarydetailService.queryAll(query);
    }
}
